package com.qcby.pushservice.base.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 演示dto
 *
 * @author cong.zhen
 * @date 2023/04/21
 */
@Data
public class DemoDTO implements Delayed, Serializable {
    private Long id;

    /**
     * 试卷编号
     */
    private String examNo;

    /**
     * 错误次数
     */
    private Integer errorNum;

    /**
     * 考试开始时间
     */
    private Date createTime;

    /**
     * 考试时长
     */
    private Long testTime;

    @Override
    public long getDelay(TimeUnit unit) {
        Long time = createTime.getTime() + testTime - Calendar.getInstance().getTimeInMillis();
        return unit.convert(time,TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return  (int)this.getDelay(TimeUnit.MILLISECONDS) - (int)o.getDelay(TimeUnit.MILLISECONDS);
    }
}
